<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMetersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('meters', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->decimal('value', 10, 2);
            $table->unsignedBigInteger('house_fee_config_id')->comment('关联配置');
            $table->foreign('house_fee_config_id')->references('id')->on('house_fee_configs')->onDelete('cascade');
            $table->unsignedBigInteger('meterable_id')->comment('关联（房间|房产|楼栋）id');
            $table->string('meterable_type')->comment("关联（房间|房产|楼栋）类型");
            $table->unsignedBigInteger('owner_item_id')->comment('关联流水')->nullable();
            $table->foreign('owner_item_id')->references('id')->on('owner_items')->onDelete('set null');
            $table->unsignedInteger('count')->comment('第几次抄表');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('meters');
    }
}
